package com.masterclient.app.modules.goods;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.masterclient.app.App;
import com.masterclient.app.R;
import java.util.List;

public class MyPagerAdapter extends PagerAdapter {
    private List<String> list;
    private Context mContext;
    private OnClickImageViewListener onClickImageViewListener;

    public MyPagerAdapter(List<String> list, Context context,OnClickImageViewListener onClickImageViewListener) {
        this.list = list;
        this.mContext = context;
        this.onClickImageViewListener = onClickImageViewListener;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
//        View view = View.inflate(mContext, R.layout.view_material_picture,null);
        ImageView imageView = new ImageView(mContext);
        imageView.setOnClickListener(view -> onClickImageViewListener.clickImageView());
        App.picasso.load(list.get(position)).fit().error(R.mipmap.defaults_1).into(imageView);
        container.addView(imageView);
        return imageView;
    }

    interface OnClickImageViewListener{
        void clickImageView();
    }
}
